import {useState, useEffect} from 'react'
import Search from '../../components/Search/index'
import HeaderTile from '../../components/HeaderTile/index'
import './style.less'

const SearchList = () => {
   const [list , setList] = useState(JSON.parse(localStorage.getItem('data')))
   useEffect(()=> {
      setList(list)
   },[list])
   const onClick = () => {
      localStorage.removeItem('data')
      let data = JSON.parse(localStorage.getItem('data'))
      setList(data)
   }
     return (
        <div>
            <HeaderTile />
            <Search/>
            <div>{list&&list.map((item,index) => <span key={index}>{item}</span>)}</div>
            {list&&list.length> 0 && <div onClick={()=> onClick()}>删除</div>}
        </div>
     )
}

export default SearchList